import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import util.IO;

/**
 * Update
 */
public class Update {
    public static void run(String configFile, String hwDir, String hwName) {
        Doraemon doraemon = new Doraemon(configFile, hwDir);
        String postFix = ".txt";
        Map<String, String> comments = doraemon.writeComment(hwName);
        for (String key : comments.keySet()) {
            String file = key + postFix;
            IO.stringToFile(file, StandardCharsets.UTF_8, comments.get(key));
        }
        Remark remark = new Remark();
        Map<String, List<String>> configMap = doraemon.getConfigMap();
        remark.setBaseNum(configMap.get("base-item-list").size());
        remark.setBaseGrade(configMap.get("base-grade").get(0));
        remark.setBasePrefix(configMap.get("base-prefix").get(0));
        remark.setPositivePrefix(configMap.get("positive-prefix").get(0));
        remark.setNegativePrefix(configMap.get("negative-prefix").get(0));
        remark.setGradelist(configMap.get("grade-list"));
        remark.run(hwDir);
    }

    public static void main(String[] args) {
        // 测试
        // javac -cp src/ -d dist/ src/Update.java
        // java -cp dist/ Update config.txt hw hw-{1:2}
        String configFile = args[0];
        String hwDir = args[1];
        String hwName = args[2];
        Update.run(configFile, hwDir, hwName);
    }
}